import axios from "axios";
import * as qs from "qs";

const post = options => {

  return new Promise((resolve, reject) => {

    const defaultOptions = {};
    const newOptions = {
      ...defaultOptions,
      ...options
    };
    newOptions.headers = {
      ...newOptions.headers
    };

    axios({
      url: newOptions.url, data: newOptions.data,
      method: 'post',
      transformRequest: [
        function (data, config) {
          return qs.stringify(data, {indices: false});
        }
      ],
      headers: newOptions.headers,

    }).then(res => {
      if (res) {
        resolve(res.data);
      }
    }).catch(err => {
      if (err.response) {
        if (err.response.status != '401' || err.response.status != '403') {
          reject(err);
        }
      } else {
        reject(err);
      }
    })

  });
};

export default post
